package com.link.base.base.invloc.service;

import com.link.base.user.model.CoreUser;
import com.link.base.base.invloc.dao.mybatis.mapper.InvImpMapper;
import com.link.base.base.invloc.model.InvImp;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.model.CallParam;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.BasicServiceImpl;
import com.link.core.util.UserUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author: unknown
 * created: unknown
 * comments:
 */
@Service
public class InvImpServiceImpl extends BasicServiceImpl<InvImp> implements InvImpService {

    @Resource
    private InvImpMapper invImpMapper;

    @Override
    public BasicMapper<InvImp> getBasicMapper() {
        return invImpMapper;
    }

    @Override
    @Transactional(rollbackFor = BasicServiceException.class)
    public void runInvImpCheck(CallParam record) throws BasicServiceException {
        try {
            CoreUser user = UserUtil.getUser();
            record.setParam1(user.getId());
            invImpMapper.runInvImpCheck(record);
        } catch (Exception e) {
            LCLogger.withException(e);
            throw new BasicServiceException(e.getMessage());
        }
    }

    @Override
    @Transactional(rollbackFor = BasicServiceException.class)
    public void runNewInvTxnForimp(CallParam record) throws BasicServiceException {
        try {
            CoreUser user = UserUtil.getUser();
            record.setParam1(user.getId());
            invImpMapper.runNewInvTxnForimp(record);
        } catch (Exception e) {
            LCLogger.withException(e);
            throw new BasicServiceException(e.getMessage());
        }
    }
}
